import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/* Router Modules */
// import componentsRouter from './modules/components'
// import chartsRouter from './modules/charts'
// import tableRouter from './modules/table'
// import nestedRouter from './modules/nested'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/order/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    noCache: true                if set true, the page will no be cached(default is false)
    affix: true                  if set true, the tag will affix in the tags-view
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
        path: '/redirect',
        component: Layout,
        hidden: true,
        children: [{
            path: '/redirect/:path(.*)',
            component: () =>
                import ('@/views/redirect/index')
        }]
    },
    {
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },
    {
        path: '/auth-redirect',
        component: () =>
            import ('@/views/login/auth-redirect'),
        hidden: true
    },
    {
        path: '/404',
        component: () =>
            import ('@/views/error-page/404'),
        hidden: true
    },
    {
        path: '/401',
        component: () =>
            import ('@/views/error-page/401'),
        hidden: true
    },
    {
        path: '/',
        redirect: '/dashboard'
    },
    {
        path: '/dashboard',
        redirect: '/dashboard/index',
        component: Layout,
        // redirect: '/dashboard',
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/dashboard/index'),
            name: 'Dashboard',
            meta: {
                title: '公司简介',
                icon: 'dashboard',
                affix: true
            }
        }]
    },
    {
        path: '/user',
        component: Layout,
        redirect: '/user/index',
        meta: {
            roles: ['admin'],
            title: '用户管理',
            icon: 'user',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/user/index'),
                name: 'User',
                meta: {
                    title: '用户管理',
                    icon: 'user',
                    noCache: true
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/user/Add'),
                name: 'UserAdd',
                hidden: true,
                meta: {
                    title: '添加用户'
                }
            },
            {
                path: 'update/:id',
                component: () =>
                    import ('@/views/user/Update'),
                name: 'UserUpdate',
                hidden: true,
                meta: {
                    title: '编辑用户'
                }
            }
        ]
    },
    {
        path: '/banner',
        component: Layout,
        redirect: 'index',
        meta: {
            roles: ['admin', 'bianji'],
            title: 'banner管理',
            icon: 'el-icon-s-order',
            noCache: true
        },
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/banner/index'),
            name: 'bannerManage',
            meta: {
                title: 'banner管理',
                noCache: true
            }
        }, {
            path: 'add',
            component: () =>
                import ('@/views/banner/Add'),
            name: 'BannerAdd',
            hidden: true,
            meta: {
                title: '添加banner',
                noCache: true,
            }
        }, {
            path: 'update/:id',
            component: () =>
                import ('@/views/banner/Add'),
            name: 'BannerUpdate',
            hidden: true,
            meta: {
                title: '编辑banner'
            }
        }]
    },
    // {
    //     path: '/staff',
    //     component: Layout,
    //     redirect: '/staff/index',
    //     meta: {
    //         title: '员工管理',
    //         icon: 'user',
    //         noCache: true
    //     },
    //     children: [{
    //             path: 'index',
    //             component: () =>
    //                 import ('@/views/staff/index'),
    //             name: 'Staff',
    //             meta: {
    //                 title: '员工管理',
    //                 icon: 'user',
    //                 noCache: true
    //             }
    //         },
    //         {
    //             path: 'add',
    //             component: () =>
    //                 import ('@/views/staff/Add'),
    //             name: 'StaffAdd',
    //             hidden: true,
    //             meta: {
    //                 title: '添加员工'
    //             }
    //         },
    //     ]
    // },
    {
        path: '/productComb',
        component: Layout,
        redirect: '/productComb/index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '基金产品组合管理',
            icon: 'documentation',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/productComb/index'),
                name: 'Product',
                meta: {
                    title: '基金产品组合管理',
                    icon: 'documentation',
                    noCache: true
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/productComb/Add'),
                name: 'productAdd',
                hidden: true,
                meta: {
                    title: '添加产品组合'
                }
            },
            {
                path: 'update/:id',
                component: () =>
                    import ('@/views/productComb/Add'),
                name: 'productUpdate',
                hidden: true,
                meta: {
                    title: '编辑产品组合'
                }
            }
        ]
    },
    {
        path: '/product',
        component: Layout,
        redirect: '/product/index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '基金产品管理',
            icon: 'documentation',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/product/index'),
                name: 'Product',
                meta: {
                    title: '基金产品管理',
                    icon: 'documentation',
                    noCache: true
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/product/Add'),
                name: 'productAdd',
                hidden: true,
                meta: {
                    title: '添加产品'
                }
            },
            {
                path: 'update/:id',
                component: () =>
                    import ('@/views/product/Add'),
                name: 'productUpdate',
                hidden: true,
                meta: {
                    title: '编辑产品'
                }
            },
            {
                path: 'data/:id',
                component: () =>
                    import ('@/views/productData/index'),
                name: 'addProductData',
                hidden: true,
                meta: {
                    title: '添加数据',
                    noCache: true
                }
            },
            {
                path: 'brief/:id',
                component: () =>
                    import ('@/views/product/brief'),
                name: 'addProductBrief',
                hidden: true,
                meta: {
                    title: '组合介绍',
                    noCache: true
                }
            },
            {
                path: 'guide/:id',
                component: () =>
                    import ('@/views/product/guide'),
                name: 'addProductGuide',
                hidden: true,
                meta: {
                    title: '购买指引',
                    noCache: true
                }
            }
        ]
    },
    {
        path: '/product0',
        component: Layout,
        redirect: '/product0/index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '政信产品管理',
            icon: 'documentation',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/product0/index'),
                name: 'Product',
                meta: {
                    title: '政信产品管理',
                    icon: 'documentation',
                    noCache: true
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/product0/Add'),
                name: 'productAdd',
                hidden: true,
                meta: {
                    title: '添加产品'
                }
            },
            {
                path: 'update/:id',
                component: () =>
                    import ('@/views/product0/Update'),
                name: 'productUpdate',
                hidden: true,
                meta: {
                    title: '编辑产品'
                }
            }
        ]
    },
    {
        path: '/order',
        component: Layout,
        redirect: '/order/index',
        meta: {
            roles: ['admin', 'yunying'],
            title: '订单管理',
            icon: 'el-icon-s-order',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/order/index'),
                name: 'Order',
                meta: {
                    title: '订单管理',
                    icon: 'el-icon-s-order',
                    noCache: true
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/order/Add'),
                name: 'orderAdd',
                hidden: true,
                meta: {
                    title: '添加订单'
                }
            },
            {
                path: 'detail/:id',
                component: () =>
                    import ('@/views/order/Detail'),
                name: 'orderDetail',
                hidden: true,
                meta: {
                    title: '订单详情'
                }
            },
            {
                path: 'update/:id',
                component: () =>
                    import ('@/views/order/Update'),
                name: 'orderUpdate',
                hidden: true,
                meta: {
                    title: '编辑订单'
                }
            }
        ]
    },
    {
        path: '/customer',
        component: Layout,
        redirect: '/customer/index',
        meta: {
            roles: ['admin', 'yunying'],
            title: '潜在客户管理',
            icon: 'user',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/customer/index'),
                name: 'Customer',
                meta: {
                    title: '潜在客户管理',
                    icon: 'user',
                    noCache: true
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/customer/Add'),
                name: 'CustomerAdd',
                hidden: true,
                meta: {
                    title: '添加客户'
                }
            },
            {
                path: 'update/:id',
                component: () =>
                    import ('@/views/customer/Add'),
                name: 'CustomerUpdate',
                hidden: true,
                meta: {
                    title: '编辑客户'
                }
            }
        ]
    },
    {
        path: '/monthCash',
        component: Layout,
        redirect: '/monthCash/index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '月兑付表',
            icon: 'user',
            noCache: true
        },
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/monthCash/index'),
            name: 'MonthCash',
            meta: {
                title: '月兑付表',
                icon: 'user',
                noCache: true
            }
        }, ]
    },
    {
        path: '/recommendProducts',
        component: Layout,
        redirect: '/recommendProducts/index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '在售产品推荐表',
            icon: 'user',
            noCache: true
        },
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/recommendProducts/index'),
            name: 'RecommendProducts',
            meta: {
                title: '在售产品推荐表',
                icon: 'user',
                noCache: true
            }
        }, ]
    },
    {
        path: '/signIn',
        component: Layout,
        redirect: '/signIn/index',
        meta: {
            roles: ['admin', 'yunying'],
            title: '签到管理',
            icon: 'user',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/signIn/index'),
                name: 'SignIn',
                meta: {
                    title: '签到客户',
                    noCache: true
                }
            },
            {
                path: 'activity',
                component: () =>
                    import ('@/views/signInActivity'),
                name: 'SignInActivity',
                meta: {
                    title: '签到活动',
                    noCache: true
                }
            },
            {
                path: 'activity/add',
                component: () =>
                    import ('@/views/signInActivity/add'),
                name: 'SignInActivityAdd',
                hidden: true,
                meta: {
                    title: '添加活动',
                    noCache: true
                }
            },
            {
                path: 'activity/detail/:id',
                component: () =>
                    import ('@/views/signInActivity/Detail'),
                name: 'SignInActivityDetail',
                hidden: true,
                meta: {
                    title: '签到活动详情',
                    noCache: true,
                }
            },
            {
                path: 'activity/update/:id',
                component: () =>
                    import ('@/views/signInActivity/add'),
                name: 'SignInActivityDetail',
                hidden: true,
                meta: {
                    title: '编辑签到活动',
                    noCache: true,
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/signIn/add'),
                name: 'SignInAdd',
                hidden: true,
                meta: {
                    title: '添加签到',
                    noCache: true,
                }
            }
        ]
    },
    {
        path: '/questionare',
        component: Layout,
        redirect: '/questionare/index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '问卷管理',
            icon: 'el-icon-s-claim',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/questionare/index'),
                name: 'questionare',
                meta: {
                    title: '问卷管理',
                    icon: 'el-icon-s-claim',
                },
            },
            {
                path: 'subject',
                component: () =>
                    import ('@/views/questionare/subject'),
                name: 'subject',
                meta: {
                    title: '题目管理',
                    icon: 'user',
                },
            },
            {
                path: 'wjAdd',
                component: () =>
                    import ('@/views/questionare/wjAdd'),
                name: 'wjAdd',
                hidden: true,
                meta: {
                    title: '添加问卷',
                    icon: 'el-icon-s-claim',
                }
            },
            {
                path: 'wjEdit/:id',
                component: () =>
                    import ('@/views/questionare/wjAdd'),
                name: 'wjEdit',
                hidden: true,
                meta: {
                    title: '编辑问卷',
                },
            },
            {
                path: 'wjDetail/:id',
                component: () =>
                    import ('@/views/questionare/wjDetail'),
                name: 'wjDetail',
                hidden: true,
                meta: {
                    title: '问卷详情',
                },
            }
        ]
    },
    {
        path: '/lottery',
        component: Layout,
        redirect: '/signIn/index',
        meta: {
            roles: ['admin', 'yunying'],
            title: '抽奖管理',
            icon: 'user',
            noCache: true
        },
        children: [{
                path: 'index',
                component: () =>
                    import ('@/views/lottery/index'),
                name: 'Lottery',
                meta: {
                    title: '抽奖管理',
                    noCache: true
                }
            },
            {
                path: 'add',
                component: () =>
                    import ('@/views/lottery/add'),
                name: 'LotteryAdd',
                hidden: true,
                meta: {
                    title: '添加抽奖',
                    noCache: true,
                }
            }
        ]
    },
    {
        path: '/video',
        component: Layout,
        redirect: 'index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '视频管理',
            icon: 'el-icon-video-play',
            noCache: true
        },
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/video/index'),
            name: 'video',
            meta: {
                title: '视频管理',
                noCache: true
            }
        }]
    },
    {
        path: '/article',
        component: Layout,
        redirect: '/article/index',
        meta: {
            roles: ['admin', 'bianji'],
            title: '文章管理',
            icon: 'el-icon-s-order',
            noCache: true
        },
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/article/index'),
            name: 'article',
            meta: {
                title: '文章管理',
                noCache: true
            }
        }, {
            path: 'add',
            component: () =>
                import ('@/views/article/Add'),
            name: 'ArticleAdd',
            hidden: true,
            meta: {
                title: '添加文章',
                noCache: true,
            }
        }, {
            path: 'update/:id',
            component: () =>
                import ('@/views/article/Add'),
            name: 'ArticleModify',
            hidden: true,
            meta: {
                title: '编辑文章',
                noCache: true,
            }
        }]
    },
    // {
    //     path: '/messageTpl',
    //     component: Layout,
    //     redirect: 'index',
    //     meta: {
    //         roles: ['admin', 'yunying'],
    //         title: '消息模板管理',
    //         icon: 'el-icon-s-order',
    //         noCache: true
    //     },
    //     children: [{
    //         path: 'index',
    //         component: () =>
    //             import ('@/views/messageTpl/index'),
    //         name: 'messageTpl',
    //         meta: {
    //             title: '消息模板管理',
    //             noCache: true
    //         }
    //     }, {
    //         path: 'add',
    //         component: () =>
    //             import ('@/views/messageTpl/Add'),
    //         name: 'messageTplAdd',
    //         hidden: true,
    //         meta: {
    //             title: '添加消息模板',
    //             noCache: true,
    //         }
    //     }, {
    //         path: 'update/:id',
    //         component: () =>
    //             import ('@/views/messageTpl/Add'),
    //         name: 'messageTplModify',
    //         hidden: true,
    //         meta: {
    //             title: '编辑消息模板',
    //             noCache: true,
    //         }
    //     }]
    // },
    {
        path: '/customerBase',
        component: Layout,
        redirect: '/customerBase/index',
        meta: {
            roles: ['admin', 'yunying'],
            title: '名单库管理',
            icon: 'el-icon-s-order',
            noCache: true
        },
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/customerBase/index'),
            name: 'customerBase',
            meta: {
                title: '名单库管理',
                noCache: true
            }
        }, {
            path: 'add',
            component: () =>
                import ('@/views/customerBase/Add'),
            name: 'customerBaseAdd',
            hidden: true,
            meta: {
                title: '添加名单库',
                noCache: true,
            }
        }, {
            path: 'update/:id',
            component: () =>
                import ('@/views/customerBase/Add'),
            name: 'customerBaseModify',
            hidden: true,
            meta: {
                title: '编辑名单库',
                noCache: true,
            }
        }]
    },
    {
        path: '/modifyPsw',
        component: Layout,
        redirect: 'index',
        meta: {
            title: '密码修改',
            icon: 'el-icon-view',
            noCache: true
        },
        children: [{
            path: 'index',
            component: () =>
                import ('@/views/modifyPsw/index'),
            name: 'modifyPsw',
            meta: {
                title: '密码修改',
                noCache: true
            }
        }]
    },
    {
        path: '*',
        component: () =>
            import ('@/views/error-page/404'),
        hidden: true
    }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */

const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({
        y: 0
    }),
    routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router
}

export default router